<div id="edit-title">更新主货品</div>
<div>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
		<input type="hidden" name="rand" value="<?php echo $form['rand']; ?>" />
		<input type="hidden" name="main_goods_id" value="<?php echo $form['main_goods']['main_goods_id']; ?>" />
		<div class="edit-name">淘宝图片</div>
		<div class="edit-image"><img src="<?php echo $form['main_goods']['taobao_image']; ?>" /></div>
		<div class="edit-name">货品类目 <?php echo form_error('type_id', '<span class="error">', '</span>'); ?></div>
		<div class="edit-select">
			<select name="type_id">
				<option>选择类目</option>
				<?php foreach ($form['types'] as $type) { ?>
				<option value="<?php echo $type->id ?>" <?php if(isset($form['main_goods']['goods_type_id'])&&$form['main_goods']['goods_type_id']==$type->id){echo 'selected';}else{echo set_select('type_id', $type->id);} ?>><?php echo $type->name ?></option>
				<?php } ?>
			</select>
		</div>
		<div class="edit-name">货号 <?php echo form_error('number', '<span class="error">', '</span>'); ?></div>
		<div class="edit-text"><input disabled type="text" name="number" value="<?php echo isset($form['main_goods']['number'])?$form['main_goods']['number']:set_value('number'); ?>" /></div>
		<div class="edit-name">货品名称 <?php echo form_error('name', '<span class="error">', '</span>'); ?></div>
		<div class="edit-text"><input type="text" name="name" value="<?php echo isset($form['main_goods']['name'])?$form['main_goods']['name']:set_value('name'); ?>" /></div>
		<div class="edit-name">搜索代码 <?php echo form_error('search_code', '<span class="error">', '</span>'); ?></div>
		<div class="edit-text"><input type="text" name="search_code" value="<?php echo isset($form['main_goods']['search_code'])?$form['main_goods']['search_code']:set_value('search_code'); ?>" /></div>
		<div class="edit-name">淘宝链接 <?php echo form_error('taobao_url', '<span class="error">', '</span>'); ?></div>
		<div class="edit-text"><input type="text" name="taobao_url" value="<?php echo isset($form['main_goods']['taobao_url'])?$form['main_goods']['taobao_url']:set_value('taobao_url'); ?>" /></div>
		<input id="sync-info" type="button" value="同步信息" />
		<div class="clear"></div>
		<div class="edit-submit"><input type="submit" value="更新" /><?php if (isset($form['result'])) { ?><div class="edit-result"><?php echo $form['result']; ?></div><?php } ?></div>
	</form>
</div>
<script type="text/javascript">
$(function(){
	$('.option').bind('click', function(){form.select._click($(this))});
})
//同步淘宝信息流程
$('input#sync-info').bind('click', function(){
	var main_goods_id = $('input[name="main_goods_id"]').val();
	var taobao_url = $('input[name="taobao_url"]').val();
	var url = site.url + 'goods/sync_taobao';
	var data = '{"main_goods_id":' + main_goods_id + ',"taobao_url":"' + taobao_url + '"}';
	data = tool.toJson(data);
	$.post(url, data, function(r){
		if ('SYNC_DONE' == r.r)
		{
			$('.edit-image img').attr('src', r.d);
			alert('同步成功');
		}
		else
		{
			alert(r.d);
		}
	},'json');
});
</script>